#ifndef actionbutton_h
#define actionbutton_h

#include "juce_amalgamated.h"
#include "MiscGraphics.h"
#include "MouseState.h"

class ActionButton: public TextButton
{
private:
protected:
	MouseState state;

	//while reusing what's already drawn
	//for subclasses to add to currently painted context
	virtual void paintMore(Graphics& g) = 0;

public:

	ActionButton(String title) :
		TextButton(title, T(""))
	{
	}

	void paintButton(Graphics& g, bool mouseOver, bool buttonDown)
	{
		Rectangle r(0, 0, getWidth(), getHeight());
		int cornerSize = 7;

		if(state.mouseOver)
			g.setColour(Colours::beige);
		if(state.mouseDown)
			g.setColour(Colours::lightgrey);
		if(!state.mouseOver && !state.mouseDown)
			g.setColour(Colours::whitesmoke);

		g.fillRoundedRectangle(r, cornerSize);
		g.setFont(getFont());
		g.setColour(Colours::black);
		g.drawFittedText(getName(), 0, 0, getWidth(), getHeight(), Justification::centred, 1);
		if(state.mouseDown) {
			g.setColour(Colours::black);
		}
		else {
			g.setColour(Colours::lightgrey);
		}
		MiscGraphics::drawRoundedRect(g, r, cornerSize, 1);
		//	g.drawRoundedRectangle(r, cornerSize, 1);

		paintMore(g);
	}

	void mouseDown(const MouseEvent& e)
	{
		state.mouseDown = true;
		repaint();
	}

	void mouseEnter(const MouseEvent& e)
	{
		state.mouseOver = true;
		setMouseCursor(MouseCursor::PointingHandCursor);
		repaint();
	}

	void mouseExit(const MouseEvent& e)
	{
		state.mouseOver = false;
		setMouseCursor(MouseCursor::NormalCursor);
		repaint();
	}

	const Font getFont()
	{
		return Font(Font::getDefaultSansSerifFontName(), 18, Font::plain);
	}

//	virtual void mouseUp(const MouseEvent& e) = 0;

};

#endif
